

export const dateTimeUtils={
    getDate(dateTime) {
        let date=new Date(dateTime);
        let year=date.getFullYear();
        /* 在日期格式中，月份是从0开始的，因此要加0
        * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
        * */
        let month= date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1;
        let day=date.getDate()<10 ? "0"+date.getDate() : date.getDate();
        let hours=date.getHours()<10 ? "0"+date.getHours() : date.getHours();
        let minutes=date.getMinutes()<10 ? "0"+date.getMinutes() : date.getMinutes();
        let seconds=date.getSeconds()<10 ? "0"+date.getSeconds() : date.getSeconds();

        return{
            formatDateByMonth:year+"-"+month+"-"+"01T00:00:00",
            formatDateByDay:year+"-"+month+"-"+day+"-"+"T00:00:00",
            year,
            month,
            day,
            hours,
            minutes,
            seconds
        }
    },
    getBusinessDateBo(dateTime,plusMinus=0,type="day"){
        if (!dateTime) {
            dateTime = new Date()
        }
        // if (typeof dateTime !== 'object') {
        //     console.log(dateTime)
        //     dateTime = dateTime.replace(/-/g, '/')
        // }
        const date = new Date(dateTime)

        if (type==="day")
            date.setDate(date.getDate() + plusMinus)
        else
            date.setMonth(date.getMonth()+plusMinus)
        let year=date.getFullYear();
        let month= date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1;
        let day=date.getDate()<10 ? "0"+date.getDate() : date.getDate();
        let hours=date.getHours()<10 ? "0"+date.getHours() : date.getHours();
        let minutes=date.getMinutes()<10 ? "0"+date.getMinutes() : date.getMinutes();
        let seconds=date.getSeconds()<10 ? "0"+date.getSeconds() : date.getSeconds();

        return{
            formatDateByMonth:year+"-"+month+"-"+"01T00:00:00",
            formatDateByDay:year+"-"+month+"-"+day+"T00:00:00",
            year,
            month,
            day,
            hours,
            minutes,
            seconds
        }
    }

}